import { DateDiffer } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属安全员',
			prop: 'staffName',
			type: 'input',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'idCard',
			type: 'input',
			span: 8,
		},
		{
			label: '过期时间',
			prop: 'expiryDateBetween',
			type: 'dateBetween',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区', prop: 'areaName' },
		{ label: '所属单位', prop: 'organizationName' },
		{ label: '所属安全员', prop: 'staffName' },
		{ label: '证书名称', prop: 'certName' },
		{
			label: '过期时间',
			prop: 'expiryDate',
		},
		{ label: '距离过期剩余天数', prop: 'diffDay' },
	],
}

export const api = {
	index: 'view_pbCertManagement_page',
	authArea: 'authArea',
}
export const baseConfig = {
	pageName: '安全人员证书管理',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'staffName',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
		mulitSet: 'mulitSet',
	},
	paramsObj: {
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	tableConfig,
	detailConfig: formConfig,
	onLoadFormate: (arr) => {
		return new Promise((resolve, reject) => {
			const temp = arr.map((item) => {
				const day = DateDiffer(item.expiryDate)
				const str = day > 0 ? `距离过期剩余${day}天` : `已过期 ${Math.abs(day)}天`
				return {
					...item,
					diffDay: day == 0 ? '今天过期' : str,
				}
			})
			resolve(temp)
		})
	},
}
